from fastapi import APIRouter, WebSocket, WebSocketDisconnect
from utils.logger_bak import logger

ws = APIRouter()


@ws.websocket("/test")
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    try:
        while True:
            data = await websocket.receive_text()
            logger.info("ws接受数据------->{}".format(data))
            await websocket.send_text(f"Message text was: {data}")
    except WebSocketDisconnect:
        pass